# -*- coding: utf-8 -*-
import KBEngine
from KBEDebug import *


class Scene(KBEngine.Entity):

    def __init__(self):
        KBEngine.Entity.__init__(self)
        self.createCellEntityInNewSpace(None)

    def loginToScene(self, entityCall):
        """
        某个Entity请求登录到该场景
        :param entityCall: 要进入本场景的实体entityCall
        """
        entityCall.createCell(self.cell)
        # 通知scene的cell部分，有人进来了
        if self.cell is not None:
            self.cell.onEnter(entityCall)

    def logoutScene(self, entityId):
        """
        某个玩家请求登出该场景
        :param entityId: 登出者的id
        """
        # 通知scene的cell部分，有人离开了
        if self.cell is not None:
            self.cell.onLeave(entityId)

    def onGetCell(self):
        """
        entity的cell部分被创建成功
        """
        props = {
            "name": "MyFirstEntity"
        }
        entity = KBEngine.createEntityLocally("FirstEntity", props)
        self.loginToScene(entity)